﻿<script type="text/javascript">
    var toolbar_wuliao = [{
        text: '新增物料',
        iconCls: 'icon-add',
        handler: function () {
            $("#wuliao-edit").dialog('open');
            $("#info-wuliaomingcheng").textbox('setValue', '');
            $("#info-wuliaoleixing").combobox('setValue', '入库物料');
            $("#info-wuliaozhuangtai").combobox('setValue', '启用');
            $("#info-shezhiquxiang").combobox('setValue', '禁用');
            $("#info-shezhifahuozhongliang").combobox('setValue', '禁用');
            $("#wuLiaoID").val('');
            $("#info-wuliaomingcheng").textbox('textbox').focus();
        }
    }, '-', {
        text: '修改物料',
        iconCls: 'icon-edit',
        handler: function () {
            var curRow = $("#xinxi_wuliao").datagrid('getSelected');
            if (curRow) {
                $("#wuLiaoID").val(curRow.id);
                $("#wuliao-edit").dialog('open');
                $("#info-wuliaomingcheng").textbox('setValue', curRow.wuliaomingcheng);
                $("#info-wuliaoleixing").combobox('setValue', curRow.wuliaoleixing);
                if (curRow.wuliaozhuangtai == "启用") {
                    $("#info-wuliaozhuangtai").combobox('setValue', '启用');
                }
                else {
                    $("#info-wuliaozhuangtai").combobox('setValue', '禁用');
                }
                if (curRow.shezhifahuozhongliang == "启用") {
                    $("#info-shezhifahuozhongliang").combobox('setValue', '启用');
                }
                else {
                    $("#info-shezhifahuozhongliang").combobox('setValue', '禁用');
                }
                if (curRow.shezhiquxiang == "启用") {
                    $("#info-shezhiquxiang").combobox('setValue', '启用');
                }
                else {
                    $("#info-shezhiquxiang").combobox('setValue', '禁用');
                }
                $("#info-wuliaomingcheng").textbox('textbox').focus();
            }
            else {
                alert("请选择要修改的物料信息。");
            }
        }
    }, '-', {
        text: '删除物料',
        iconCls: 'icon-remove',
        handler: function () {
            $("#wuliao-dlg").dialog('open');
        }
    }];

    function submitWuLiaoForm() {
        var wuliaomingchneg = $("#info-wuliaomingcheng").textbox('getText');
        var wuliaoleixing = $("#info-wuliaoleixing").combobox('getText');
        var wuliaozhuangtai = $("#info-wuliaozhuangtai").combobox('getText');
        var quxiang = $("#info-shezhiquxiang").combobox('getText');
        var shezhifahuozhongliang = $("#info-shezhifahuozhongliang").combobox('getText');
        var wuliaoid = $("#wuLiaoID").val();
        if (wuliaomingchneg && wuliaoleixing && wuliaozhuangtai && quxiang && shezhifahuozhongliang) {
            $.post("handler/xinxi_wuliao.ashx", { uid: window.uid, kid: window.kid, wuLiaoType: "2", wuLiaoID: wuliaoid, wuliaomingcheng: wuliaomingchneg, wuliaoleixing: wuliaoleixing, wuliaozhuangtai: wuliaozhuangtai, shezhiquxiang: quxiang, shezhifahuozhongliang: shezhifahuozhongliang }, function (data, status) {
                if (data == "OK") {
                    $("#wuliao-edit").dialog('close');
                    $("#xinxi_wuliao").datagrid('load');
                    return;
                }
                if (data == "Failed") {
                    alert("保存物料信息失败，请重试");
                    return;
                }
                alert(data);
            });
        }
        else {
            alert("信息不完整，请检查重试。");
        }
    }

    function clearWuLiaoForm() {
        $("#wuliao-edit").dialog('close');
    }

    function DelWuLiao() {
        var curRow = $("#xinxi_wuliao").datagrid('getSelected');
        if (curRow) {
            $.post('handler/xinxi_wuliao.ashx', { wuLiaoType: "3", wuLiaoID: curRow.id, uid: window.uid, kid: window.kid }, function (data, status) {
                if (data == "OK") {
                    $("#wuliao-dlg").dialog('close');
                    $("#xinxi_wuliao").datagrid('load');
                    return;
                }
                if (data == "Failed") {
                    alert("删除物料信息失败，请重试");
                    $("#wuliao-dlg").dialog('close');
                    return;
                }
                alert(data);
                $("#wuliao-dlg").dialog('close');
            });
        }
        else {
            alert("请选择要删除的物料信息。");
        }
    }

    var toolbar_xinghao = [{
        text: '新增型号',
        iconCls: 'icon-add',
        handler: function () {
            var curRow = $("#xinxi_wuliao").datagrid('getSelected');
            if (curRow) {
                $("#xinghao-edit").dialog('open');
                $("#info-xinghao").textbox('setValue', '');
                $("#info-morenkouzhong").textbox('setValue', '0');
                $('#info-kouzhongfangshi').combobox('setValue', '普通扣重');
                $('#info-huansuangongshi').textbox('setValue', '');
                $('#info-pianchazhuangtai').combobox('setValue', '禁用');
                $("#info-pianchazhongliang").textbox('setValue', '0');
                $("#xingHaoID").val("");
                $("#info_shuiwenliao_guanlian").combobox('setValue', '—不关联—');
                $("#info_hunningtu_guanlian").combobox('setValue', '—不关联—');
                $("#info_liqingliao_guanlian").combobox('setValue', '—不关联—');
            }
            else {
                alert("请先选择所属的物料信息。");
            }
        }
    }, '-', {
        text: '修改型号',
        iconCls: 'icon-edit',
        handler: function () {
            var curRow = $("#xinxi_xinghao").datagrid('getSelected');
            if (curRow) {
                $("#xingHaoID").val(curRow.id);
                $("#xinghao-edit").dialog('open');
                $("#info-xinghao").textbox('setValue', curRow.xinghao);
                $("#info-morenkouzhong").textbox('setValue', curRow.morenkouzhong);
                $('#info-kouzhongfangshi').combobox('setValue', curRow.kouzhongfangshi);
                $('#info-huansuangongshi').textbox('setValue', curRow.huansuangongshi);
                $('#info-pianchazhuangtai').combobox('setValue', curRow.pianchazhuangtai);
                $("#info-pianchazhongliang").textbox('setValue', curRow.pianchazhongliang);
                $("#info_shuiwenliao_guanlian").combobox('setValue', curRow.shuiwenliao);
                $("#info_hunningtu_guanlian").combobox('setValue', curRow.hunningtu);
                $("#info_liqingliao_guanlian").combobox('setValue', curRow.liqingliao);
            }
            else {
                alert("请选择要修改的物料信息。");
            }
        }
    }, '-', {
        text: '删除型号',
        iconCls: 'icon-remove',
        handler: function () {
            $("#xinghao-dlg").dialog("open");
        }
    }];

    function submitXingHaoForm() {
        var xinghao = $("#info-xinghao").textbox('getText');
        var morenkouzhong = $("#info-morenkouzhong").textbox('getText');
        var kouzhongfangshi = $("#info-kouzhongfangshi").combobox('getText');
        var huansuangongshi = $("#info-huansuangongshi").textbox('getText');
        var pianchazhuangtai = $("#info-pianchazhuangtai").combobox('getText');
        var pianchazhongliang = $("#info-pianchazhongliang").textbox('getText');
        var wuliaoRow = $("#xinxi_wuliao").datagrid('getSelected');
        var wuliaobianhao = wuliaoRow.id;
        var xinghaoid = $("#xingHaoID").val();
        var shuiwenliao = $("#info_shuiwenliao_guanlian").combobox('getText');
        var hunningtu = $("#info_hunningtu_guanlian").combobox('getText');
        var liqingliao = $("#info_liqingliao_guanlian").combobox('getText');
        if (xinghao && morenkouzhong && pianchazhongliang) {
            $.post("handler/xinxi_xinghao.ashx", { uid: window.uid, kid: window.kid, xingHaoType: '2',xingHaoID:xinghaoid,wuLiaoBianHao:wuliaobianhao,xinghao:xinghao,morenkouzhong:morenkouzhong,kouzhongfangshi:kouzhongfangshi,huansuangongshi:huansuangongshi,pianchazhuangtai:pianchazhuangtai,pianchazhongliang:pianchazhongliang,shuiwenliao:shuiwenliao,hunningtu:hunningtu,liqingliao:liqingliao}, function (data, status) {
                if (data == "OK") {
                    $("#xinghao-edit").dialog('close');
                    $("#xinxi_xinghao").datagrid('load');
                    return;
                }
                if (data == "Failed") {
                    alert("保存物料型号信息失败，请重试");
                    return;
                }
                alert(data);
            });
        }
        else {
            alert("信息不完整，请检查重试。");
        }
    }

    function clearXingHaoForm() {
        $("#xinghao-edit").dialog('close');
    }


    function DelXingHao() {
        var curRow = $("#xinxi_xinghao").datagrid('getSelected');
        if (curRow) {
            $.post('handler/xinxi_xinghao.ashx', { xingHaoType: "3", xingHaoID: curRow.id, wuLiaoBianHao: "empty", uid: window.uid, kid: window.kid }, function (data, status) {
                if (data == "OK") {
                    $("#xinghao-dlg").dialog('close');
                    $("#xinxi_xinghao").datagrid('load');
                    return;
                }
                if (data == "Failed") {
                    alert("删除物料信息失败，请重试");
                    $("#xinghao-dlg").dialog('close');
                    return;
                }
                alert(data);
                $("#xinghao-dlg").dialog('close');
            });
        }
        else {
            alert("请选择要删除的物料型号信息。");
        }
    }

    $(function () {
        $("#xinxi_wuliao").datagrid({
            border: false, singleSelect: true, collapsible: false, striped: true, toolbar: toolbar_wuliao, url: 'handler/xinxi_wuliao.ashx', method: 'post', queryParams: { wuLiaoType: '1', uid: window.uid, kid: window.kid }, height: 350, onSelect: function (index, row) {
                $("#xinxi_xinghao").datagrid("load", { xingHaoType: "1", wuLiaoBianHao: row.id, uid: window.uid, kid: window.kid });
            }
        });
        $("#xinxi_xinghao").datagrid({
            url: 'handler/xinxi_xinghao.ashx', method: 'post', border: false, singleSelect: true, collapsible: false, striped: true, toolbar: toolbar_xinghao, uid: window.uid, kid: window.kid
        });

        $("#info_shuiwenliao_guanlian").combobox({
            url: 'handler/xinxi_zidian.ashx',
            method: 'post',
            queryParams: {
                uid: window.uid,
                kid: window.kid,
                ziDianType: '1',
                fenZu: '水稳料'
            },
            valueField: 'xiangmu',
            textField: 'xiangmu',
            panelWidth: 200,
            panelHeight: '200',
            editable: false,
            loadFilter: function (data)
            {
                var d = [{ 'xiangmu': '—不关联—' }];
                for (var i = 0; i < data.length; i++)
                {
                    d.push(data[i]);
                }
                return d;
            }
        });
        $("#info_hunningtu_guanlian").combobox({
            url: 'handler/xinxi_zidian.ashx',
            method: 'post',
            queryParams: {
                uid: window.uid,
                kid: window.kid,
                ziDianType: '1',
                fenZu: '混凝土'
            },
            valueField: 'xiangmu',
            textField: 'xiangmu',
            panelWidth: 200,
            panelHeight: 'auto',
            editable: false,
            loadFilter: function (data) {
                var d = [{ 'xiangmu': '—不关联—' }];
                for (var i = 0; i < data.length; i++) {
                    d.push(data[i]);
                }
                return d;
            }
        });
        $("#info_liqingliao_guanlian").combobox({
            url: 'handler/xinxi_zidian.ashx',
            method: 'post',
            queryParams: {
                uid: window.uid,
                kid: window.kid,
                ziDianType: '1',
                fenZu: '沥青料'
            },
            valueField: 'xiangmu',
            textField: 'xiangmu',
            panelWidth: 200,
            panelHeight: 'auto',
            editable: false,
            loadFilter: function (data) {
                var d = [{ 'xiangmu': '—不关联—' }];
                for (var i = 0; i < data.length; i++) {
                    d.push(data[i]);
                }
                return d;
            }
        });
    });
</script>

<table id="xinxi_wuliao" style=" width:100%" class="" title="物料管理" data-options="">
    <thead>
        <tr>
            <th data-options="field:'wuliaomingcheng',width:100">
                物料名称
            </th>
            <th data-options="field:'wuliaoleixing',width:100">
                物料类型
            </th>
            <th data-options="field:'wuliaozhuangtai',width:100">
                状态
            </th>
            <th data-options="field:'shezhifahuozhongliang',width:120">
                设置发货重量
            </th>
            <th data-options="field:'shezhiquxiang',width:120">
                设置去向标段
            </th>
            <th data-options="field:'id',hidden:true">
                编号
            </th>
        </tr>
    </thead>
</table>
<table id="xinxi_xinghao" style="width:100%" class="" title="物料型号" data-options="">
    <thead>
        <tr>
            <th data-options="field:'xinghao',width:100">
                型号
            </th>
            <th data-options="field:'morenkouzhong',width:100">
                默认扣重
            </th>
            <th data-options="field:'kouzhongfangshi',width:100">
                扣重方式
            </th>
            <th data-options="field:'huansuangongshi',width:250">
                方量换算公式
            </th>
            <th data-options="field:'pianchazhongliang',width:100">
                偏差重量
            </th>
            <th data-options="field:'pianchazhuangtai',width:100">
                偏差状态
            </th>
            <th data-options="field:'shuiwenliao',width:100">
                水稳料关联
            </th>
            <th data-options="field:'hunningtu',width:100">
                混凝土关联
            </th>
            <th data-options="field:'liqingliao',width:100">
                沥青料关联
            </th>
            <th data-options="field:'id',hidden:true">
                编号
            </th>
        </tr>
    </thead>
</table>
<div id="wuliao-edit" class="easyui-dialog" title="单位信息编辑" data-options="modal:true,closed:true,iconCls:'icon-edit',draggable:false,collapsible:false,minimizable:false,maximizable:false,resizable:false"
     style="width: 500px; height: 350px; padding: 10px;">
    <div style="width: 350px; margin: 0 auto;">
        <table cellpadding="5" style="font-size: 13px; margin: 0 auto; padding-top: 20px">
            <tr>
                <td>
                    物料名称:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-wuliaomingcheng" name="info-wuliaomingcheng"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    物料类型:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-wuliaoleixing" id="info-wuliaoleixing"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                        <option value="入库物料">入库物料</option>
                        <option value="出库物料">出库物料</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    状态:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-wuliaozhuangtai" id="info-wuliaozhuangtai"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                        <option value="启用">启用</option>
                        <option value="禁用">禁用</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    设置发货重量:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-shezhifahuozhongliang" id="info-shezhifahuozhongliang"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                        <option value="启用">启用</option>
                        <option value="禁用">禁用</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    设置去向:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-shezhiquxiang" id="info-shezhiquxiang"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                        <option value="启用">启用</option>
                        <option value="禁用">禁用</option>
                    </select>
                </td>
            </tr>
        </table>
        <input type="hidden" name="wuLiaoID" id="wuLiaoID" value="" />
        <div style="text-align: center; padding: 5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="submitWuLiaoForm()"
               data-options="iconCls:'icon-ok'">保存</a> <a href="javascript:void(0)" class="easyui-linkbutton"
                                                          style="width: 75px" onclick="clearWuLiaoForm()" data-options="iconCls:'icon-cancel'">关闭</a>
        </div>
    </div>
</div>
<div id="wuliao-dlg" class="easyui-dialog" title="删除确认" style="width: 300px; height: 150px;padding: 10px" data-options="iconCls: 'icon-help',buttons: '#wuliao-dlg-buttons',modal:true,closed:true">
    确定要删除该物料信息吗？
</div>
<div id="wuliao-dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:DelWuLiao();">
        确定
    </a> <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#wuliao-dlg').dialog('close')">
        取消
    </a>
</div>
<div id="xinghao-edit" class="easyui-dialog" title="物料型号信息编辑" data-options="modal:true,closed:true,iconCls:'icon-edit',draggable:false,collapsible:false,minimizable:false,maximizable:false,resizable:false"
     style="width: 500px; height: 450px; padding: 10px;">
    <div style="width: 350px; margin: 0 auto;">
        <table cellpadding="5" style="font-size: 13px; margin: 0 auto; padding-top: 20px">
            <tr>
                <td>
                    型号名称:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-xinghao" name="info-xinghao" data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    默认扣重:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-morenkouzhong" name="info-morenkouzhong"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    扣重方式:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-kouzhongfangshi" id="info-kouzhongfangshi"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                        <option value="普通扣重">普通扣重</option>
                        <option value="百分比扣重">百分比扣重</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    换算公式:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-huansuangongshi" name="info-huansuangongshi"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    偏差重量:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-pianchazhongliang" name="info-pianchazhongliang"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    偏差状态:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-pianchazhuangtai" id="info-pianchazhuangtai"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                        <option value="启用">启用</option>
                        <option value="禁用">禁用</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    水稳料关联:
                </td>
                <td>
                    <select class="easyui-combobox" name="info_shuiwenliao_guanlian" id="info_shuiwenliao_guanlian"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    混凝土关联:
                </td>
                <td>
                    <select class="easyui-combobox" name="info_hunningtu_guanlian" id="info_hunningtu_guanlian"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    沥青料关联:
                </td>
                <td>
                    <select class="easyui-combobox" name="info_liqingliao_guanlian" id="info_liqingliao_guanlian"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                    </select>
                </td>
            </tr>
        </table>
        <input type="hidden" name="xingHaoID" id="xingHaoID" value="" />
        <div style="text-align: center; padding: 5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="submitXingHaoForm()"
               data-options="iconCls:'icon-ok'">保存</a> <a href="javascript:void(0)" class="easyui-linkbutton"
                                                          style="width: 75px" onclick="clearXingHaoForm()" data-options="iconCls:'icon-cancel'">
                关闭
            </a>
        </div>
    </div>
</div>

<div id="xinghao-dlg" class="easyui-dialog" title="删除确认" style="width: 300px; height: 150px; padding: 10px" data-options="iconCls:'icon-help' ,buttons:'#xinghao-dlg-buttons',modal:true,closed:true">
    确定要删除该物料型号信息吗？
</div>
<div id="xinghao-dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:DelXingHao();">
        确定
    </a> <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#xinghao-dlg').dialog('close')">
        取消
    </a>
</div>
